package com.its.common.net.server.channel;

import io.netty.channel.Channel;
import io.netty.channel.ChannelId;
import io.netty.util.AttributeKey;

import java.util.List;
import java.util.Optional;

/**
 * @Author xiaxp
 * @Date 9/1/22 17:33
 * @Description
 */
public class ChannelHelper {

    private static ChannelManager channelManager = DefaultChannelManager.getInstance();

    public static ChannelWrapper getChannelWrapper(Channel channel) {
        return getChannelWrapper(channel.id());
    }

    public static ChannelWrapper getChannelWrapper(ChannelId channelId) {
        return channelManager.getChannelWrapper(channelId);
    }

    public static void closeChannel(ChannelId channelId) {
        channelManager.removeChannel(channelId);
    }

    public static void closeChannel(Channel channel) {
        closeChannel(channel.id());
    }

    public static List<Channel> getAllChannels(){
        return channelManager.getAllChannels();
    }

    public static Channel getChannelFromChannelId(ChannelId channelId){
        return channelManager.getChannelFromChannelId(channelId);
    }

    public static Channel getChannelFromAddrAndPort(String addr, int port){
        return channelManager.getChannelFromAddrAndPort(addr, port);
    }

    public static Optional<Channel> filterByAttribute(AttributeKey key, String attr){
        return channelManager.filterByAttribute(key, attr);
    }
}
